import Mock from 'mockjs';

Mock.setup({
    timeout: '200-600'
});
const addSigns = Mock.mock('/signs', 'post', {
    "code": "0000",
    "message": "操作成功",
    "data": {
        "data": [
            {
                "id": 1,
                "sign_no": "QS20180531001",
                "signed_date": "2018-05-31",
                "purchaser_name": "重庆强兵实业有限公司"
            }
        ]
    }
});

const supplierSigns = Mock.mock(/\/supplier-signs\?tab=\d+.*$/, 'get', {
    "code": "0000",
    "message": "操作成功",
    "data": {
        "data|100": [
            {
                'id|+1': 1,
                "sign_no": "QS20180531001",
                "signed_date": "@date('yyyy-MM-dd')",
                "purchaser_name": "重庆强兵实业有限公司"
            }
        ],
        "total|10-100": 1,
        "current_page": 1,
        "last_page": 12,
        "per_page": 10
    }
});

const supplierBubbles = Mock.mock(/\/supplier-signs\/bubbles\?tab=.*$/, 'get', opt => {
    let ids = opt.url.split('?')[1].split('&')[0].split('=')[1].split(',');
    let res = {
        "code": "0000",
        "message": "操作成功"
    }
    let data = {};
    ids.forEach(id => {
        data[id] = Math.ceil(Math.random() * 100);
    });
    res.data = data;
    return res;
});

const supplierDetail = Mock.mock(/\/supplier-signs\/\d+$/, 'get', {
    "code": "0000",
    "message": "操作成功",
    "data": {
        "sign": {
            "sign_no": "QS20180531001",
            "signed_date": "2018-05-31",
            "supplier_id": 12,
            "supplier_name": "重庆宗申汽车配件有限公司",
            "purchaser_id": 12,
            "purchaser_name": "重庆强兵实业有限公司",
            "status_name": "待确认",
            "materials": [
                {
                    "purchaser_sign_id": 5,
                    "category_id": 1,
                    "category_name": "钢材",
                    "material_id": 10,
                    "material_info": "{'name':'角钢1号','model':'8分','code':'33683'}",
                    "brand": "宝钢",
                    "unit": "吨",
                    "price": 1000.88,
                    "quantity": 500.25,
                    "is_taxed": 1,
                    "tax_rate": 17,
                    "status_name": "待确认",
                    "remark": "打回去"
                }
            ]
        },
        "options": {
            "material_id": {
                "brand": [
                    "宝钢"
                ],
                "unit": [
                    "吨"
                ],
                "tax_rate": [
                    17
                ]
            }
        }
    }
});

const supplierCommit = Mock.mock(/\/supplier-signs\/\d+\/commit$/, 'post', opt => {
    let res = {
        "code": "0000",
        "message": "操作成功",
        "data": [
            {
                "sign_no": "QS20180531001",
                "signed_date": "2018-05-31",
                "supplier_id": Number(opt.url.split('/')[2]),
                "supplier_name": "重庆宗申汽车配件有限公司",
                "purchaser_id": "重庆强兵实业有限公司",
                "status_name": "待确认",
                "materials": [
                    {
                        "purchaser_sign_id": 5,
                        "category_id": 1,
                        "category_name": "钢材",
                        "material_id": 10,
                        "material_info": "{'name':'角钢1号','model':'8分','code':'33683'}",
                        "brand": "宝钢",
                        "unit": "吨",
                        "price": 1000.88,
                        "quantity": 500.25,
                        "is_taxed": 1,
                        "tax_rate": 17,
                        "status_name": "待确认",
                        "remark": "打回去"
                    }
                ]
            }
        ]
    }
    return res;
});

const supplierCancel = Mock.mock(/\/supplier-signs\/\d+\/cancel$/, 'post', {
    "code": "0000",
    "message": "操作成功",
    "data": {}
});

const purchaserSigns = Mock.mock(/\/purchaser-signs\?tab=\d+.*$/, 'get', {
    "code": "0000",
    "message": "操作成功",
    "data": {
        "data|5": [
            {
                'id|+1': 1,
                "sign_no": "QS20180531001",
                "signed_date": "@date('yyyy-MM-dd')",
                "purchaser_name": "重庆强兵实业有限公司"
            }
        ],
        "total|10-100": 1,
        "current_page": 1,
        "last_page": 12,
        "per_page": 10
    }
});

const purchaserBubbles = Mock.mock(/\/purchaser-signs\/bubbles\?tab=.*$/, 'get', opt => {
    let ids = opt.url.split('?')[1].split('&')[0].split('=')[1].split(',');
    let res = {
        "code": "0000",
        "message": "操作成功"
    }
    let data = {};
    ids.forEach(id => {
        data[id] = Math.ceil(Math.random() * 100);
    });
    res.data = data;
    return res;
});

const purchaserDetail = Mock.mock(/\/purchaser-signs\/\d+$/, 'get', {
    "code": "0000",
    "message": "操作成功",
    "data": {
        "sign": {
            "sign_no": "QS20180531001-1",
            "signed_date": "2018-05-31",
            "supplier_id": 12,
            "supplier_name": "重庆宗申汽车配件有限公司",
            "purchaser_id": 15,
            "purchaser_name": "重庆强兵实业有限公司",
            "status_name": "待确认",
            "materials": [
                {
                    "supplier_sign_id": 25,
                    "category_id": 11,
                    "category_name": "钢材",
                    "material_id": 25,
                    "material_info": "{'name':'角钢1号','model':'8分','code':'33683'}",
                    "brand": "宝钢",
                    "unit": "吨",
                    "price": 1000.28,
                    "quantity": 500.25,
                    "is_taxed": 1,
                    "tax_rate": 17,
                    "status_name": "待确认"
                }
            ]
        }
    }
});

const purchaserConfirm = Mock.mock(/\/purchaser-signs\/\d+\/confirm$/, 'post', {
    "code": "0000",
    "message": "操作成功",
    "data": {}
});

const purchaserReject = Mock.mock(/\/purchaser-signs\/\d+\/reject$/, 'post', {
    "code": "0000",
    "message": "操作成功",
    "data": {}
});

export default {
    purchaserReject,
    purchaserConfirm,
    purchaserDetail,
    purchaserBubbles,
    purchaserSigns,
    supplierCancel,
    supplierCommit,
    supplierDetail,
    supplierBubbles,
    supplierSigns,
    addSigns
}